//
//  MomentsBodyView.m
//  AnimationRecommend
//
//  Created by 花花蔡 on 2017/2/22.
//  Copyright © 2017年 ljm. All rights reserved.
//

#import "MomentsBodyView.h"

@interface MomentsBodyView ()

@property(nonatomic,strong) UIImageView *iconImageView;
@property(nonatomic,strong) UILabel *nikeNameLabel;
@property(nonatomic,strong) UILabel *createTime;
@property(nonatomic,strong) UILabel *textLabel;
@property(nonatomic,strong) PYPhotosView *photosView;


@end

@implementation MomentsBodyView


- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self setChildView];
    }
    
    return self;
}

- (void)setChildView {
    
    _iconImageView = [[UIImageView alloc] init];
    [self addSubview:_iconImageView];
    
    _nikeNameLabel = [[UILabel alloc] init];
    _nikeNameLabel.font = momentsBodyCellNikeNameFont;
    [self addSubview:_nikeNameLabel];
    
    _createTime = [[UILabel alloc] init];
    _createTime.font = momentsBodyCellTimeFont;
    [self addSubview:_createTime];
    
    _textLabel = [[UILabel alloc] init];
    _textLabel.font = momentsBodyCellTextFont;
    [self addSubview:_textLabel];
    _textLabel.numberOfLines = 0;
    
    // 图片
    // 创建一个流水布局photosView（默认为流水布局）
    _photosView = [PYPhotosView photosView];
    _photosView.scrollEnabled = NO;
    _photosView.photoWidth = circleCellPhotosWH;
    _photosView.photoHeight = circleCellPhotosWH;
    _photosView.photoMargin = circleCellPhotosMargin;
    [self addSubview:_photosView];
}

-(void)setMomentFrames:(MomentsViewModel *)momentFrames {
    _momentFrames = momentFrames;
    //给子控件赋值
    [self setData];
    //给子控件设置frame
    [self setFrame];

    //如果没有图片则隐藏 图片View
    if ([[self.momentFrames.moment.photos objectAtIndex:0] count] != 0) {
        self.photosView.hidden = NO;
        // 设置图片缩略图数组
        self.photosView.thumbnailUrls = _momentFrames.moment.photos.firstObject;
        // 设置图片原图地址
        self.photosView.originalUrls = _momentFrames.moment.photos.lastObject;
        // 设置图片frame
        self.photosView.frame = _momentFrames.bodyPhotoFrame;
        [self.photosView reloadInputViews];
    }else{
        self.photosView.hidden = YES;
    }
}


-(void)setData{
    
    self.iconImageView.image = [UIImage imageNamed:_momentFrames.moment.iconImage];
    self.nikeNameLabel.text = _momentFrames.moment.userName;
    self.textLabel.text = _momentFrames.moment.text;
    self.createTime.text = _momentFrames.moment.createdAt;
    NSURL *url = [NSURL URLWithString:_momentFrames.moment.iconImage];
    [self.iconImageView sd_setImageWithURL:url];
}

-(void)setFrame{
    
    self.iconImageView.frame = _momentFrames.bodyIconFrame;
    self.nikeNameLabel.frame = _momentFrames.bodyNameFrame;
    self.textLabel.frame = _momentFrames.bodyTextFrame;
    self.createTime.frame = _momentFrames.bodyTimeFrame;
    
}





@end
